package com.controller;
import com.entity.AsCustoms;
import com.entity.AsSystemConfig;
import com.entity.MethodLog;
import com.service.AsSystemConfigService;
import com.utils.AnnotationUtil;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class SystemConfigController
{
    @Resource
    private AsSystemConfigService asSystemConfigService;

    //前往财务类型页面
    @RequestMapping( value = "/toFinancialTypePage" )
    public String toFinancialTypePage()
    {
        return "systemConfigManage/financialType";
    }

    //前往客户类型页面
    @RequestMapping( value = "/toCustomTypePage" )
    public String toCustomTypePage()
    {
        return "systemConfigManage/customType";
    }

    //前往证件类型页面
    @RequestMapping( value = "/toCertificateTypePage" )
    public String toCertificateTypePage()
    {
        return "systemConfigManage/certificateType";
    }

    //前往服务类型页面
    @RequestMapping( value = "/toServiceTypePage" )
    public String toServiceTypePage()
    {
        return "systemConfigManage/serviceType";
    }

    //前往服务年限页面
    @RequestMapping( value = "/toServiceYearsPage" )
    public String toServiceYearsPage()
    {
        return "systemConfigManage/serviceYears";
    }

    //前往app地址页面
    @RequestMapping( value = "/toAppAddressPage" )
    public String toAppAddressPage()
    {
        return "systemConfigManage/appAddress";
    }

    //前往优惠类型页面
    @RequestMapping( value = "/toPreferenceTypePage" )
    public String toPreferenceTypePage()
    {
        return "systemConfigManage/preferenceType";
    }

    //前往APP价格配置页面
    @RequestMapping( value = "/toAppConfigPage" )
    public String toAppConfigPage()
    {
        return "systemConfigManage/appConfig";
    }

    //显示不同配置类型管理页面datagrid
    @RequestMapping( value = "/showDateGrid" , produces = "application/json;charset=UTF-8" )
    @ResponseBody
    @MethodLog( operateInfo = "" )
    public String showDateGrid(
            Integer page ,
            @RequestParam( value = "rows" ) Integer size ,
            Integer configType )
    {
        String [] operateType = { "财务类型" , "服务类型" , "服务年限" , "APP地址" , "客户类型" , "证件类型" , "优惠类型" , "开通APP价格配置" };
        String operateInfo = "查看" + operateType[configType-1];
        String methodName = "showDateGrid";
        Class [] classes = new Class[]{ Integer.class , Integer.class , Integer.class };
        String jsonStr = asSystemConfigService.returnDateGridJsonStr( configType , page , size );
        //根据操作动态修改OperateInfo注解值
        AnnotationUtil.setOperateInfo( SystemConfigController.class , methodName , operateInfo , classes );

        return jsonStr;
    }

    //查询配置类型
    @RequestMapping( value = "/selectConfig" , produces = "application/json;charset=UTF-8" )
    @ResponseBody
    @MethodLog( operateInfo = "" )
    public String selectConfig( Integer configId , Integer configType )
    {
        String operateInfo = "";
        switch( configType )
        {
            case 3:
                operateInfo = "查看服务年限";
                break;
            case 4:
                operateInfo = "查看APP地址";
                break;
            case 8:
                operateInfo = "查看开通APP价格配置";
                break;
        }
        String methodName = "selectConfig";
        Class [] classes = new Class[]{ Integer.class , Integer.class };
        String jsonStr = asSystemConfigService.returnOneById( configId );
        AnnotationUtil.setOperateInfo( SystemConfigController.class , methodName , operateInfo , classes );

        return jsonStr;
    }

    //修改配置类型
    @RequestMapping( value = "/updateConfig" , produces = "application/json;charset=UTF-8" )
    @ResponseBody
    @MethodLog( operateInfo = "" )
    public String updateConfig( AsSystemConfig config )
    {
        String [] operateType = { "财务类型" , "服务类型" , "服务年限" , "APP地址" , "客户类型" , "证件类型" , "优惠类型" , "开通APP价格配置" };
        String methodName = "updateConfig";
        Class [] classes = new Class[]{ AsSystemConfig.class };
        String operateInfo = "更新" + operateType[config.getConfigType()-1];
        String jsonStr = asSystemConfigService.update( config );
        AnnotationUtil.setOperateInfo( SystemConfigController.class , methodName , operateInfo , classes );

        return jsonStr;
    }

    //添加配置类型
    @RequestMapping( value = "/addConfig" , produces = "application/json;charset=UTF-8" )
    @ResponseBody
    @MethodLog( operateInfo = "" )
    public String addConfig( AsSystemConfig config )
    {
        String [] operateType = { "财务类型" , "服务类型" , "服务年限" , "APP地址" , "客户类型" , "证件类型" , "优惠类型" , "开通APP价格配置" };
        String methodName = "addConfig";
        Class [] classes = new Class[]{ AsSystemConfig.class };
        String operateInfo = "添加" + operateType[config.getConfigType()-1];
        String jsonStr = asSystemConfigService.add( config );
        AnnotationUtil.setOperateInfo( SystemConfigController.class , methodName , operateInfo , classes );

        return jsonStr;
    }

    //删除配置类型
    @RequestMapping( value = "/delConfig" , produces = "application/json;charset=UTF-8" )
    @ResponseBody
    @MethodLog( operateInfo = "" )
    public String delConfig( Integer configId , Integer configType )
    {
        String [] operateType = { "财务类型" , "服务类型" , "服务年限" , "APP地址" , "客户类型" , "证件类型" , "优惠类型" , "开通APP价格配置" };
        String methodName = "delConfig";
        Class [] classes = new Class[]{ Integer.class , Integer.class };
        String operateInfo = "删除" + operateType[configType-1];
        String jsonStr = asSystemConfigService.del( configId );
        AnnotationUtil.setOperateInfo( SystemConfigController.class , methodName , operateInfo , classes );

        return jsonStr;
    }

}
